package com.secure.core.entity;

import java.io.Serializable;

import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.springframework.util.Assert;

import com.secure.core.generate.LongSerializer;
import com.secure.core.mybatis.MyBatisColumn;
import com.secure.core.mybatis.MybatisID;

public class BaseEntity<T extends BaseEntity<T>>{
	@MybatisID
	@MyBatisColumn(value="ID")
	@JsonSerialize(using=LongSerializer.class)
	protected Long id;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
//		Assert.notNull(id);
		this.id = (Long)id;
	}
	
	public void setId(Serializable id) {
		Assert.notNull(id);
		this.id = (Long)id;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		BaseEntity<?> other = (BaseEntity<?>) obj;
		if (getId() == null) {
			if (other.getId() != null)
				return false;
		} else if (!getId().equals(other.getId()))
			return false;
		return true;
	}
	
}
